import math

"""
This class defines the cell index.
"""
class Cell:
    
    def __init__(self, xIndex, yIndex, value):
        self.xIndex = xIndex
        self.yIndex = yIndex
        self.value = value
    
    """
    
    """
    def __area__(self, xIndex, yIndex):
        if xIndex >=0 and yIndex >= 0:
            return 1
        elif xIndex >=0 and yIndex <= 0:
            return 2
        elif xIndex <=0 and yIndex <= 0:
            return 3
        elif xIndex <=0 and yIndex >= 0:
            return 4
    
    """
      4  5  6  7 | 8  9  10 11
      3          |          12
      2  area 1  |  area 2  13
      1          |          14
    ------------ . ------------
     26          |          15
     25  area 4  |  area 3  16
     24          |          17
     23 22   21  |  20  19  18
    """
    def __cmpInSameArea__(self, other, areaNo):
        if areaNo == 1:
            if self.xIndex > other.xIndex:
                return 1
            elif self.xIndex == other.xIndex:
                if self.yIndex > other.yIndex:
                    return 1
                elif self.yIndex < other.yIndex:
                    return - 1
                else:
                    return 0
            else:
                return - 1
        elif areaNo == 2:
            if self.xIndex < other.xIndex:
                return 1
            elif self.xIndex == other.xIndex:
                if self.yIndex < other.yIndex:
                    return 1
                elif self.yIndex > other.yIndex:
                    return - 1
                else:
                    return 0
            else:
                return - 1
        elif areaNo == 3:
            if self.xIndex < other.xIndex:
                return 1
            elif self.xIndex == other.xIndex:
                if self.yIndex < other.yIndex:
                    return 1
                elif self.yIndex > other.yIndex:
                    return - 1
                else:
                    return 0
            else:
                return - 1
        else:
            if self.xIndex > other.xIndex:
                return 1
            elif self.xIndex == other.xIndex:
                if self.yIndex > other.yIndex:
                    return 1
                elif self.yIndex < other.yIndex:
                    return - 1
                else:
                    return 0
            else:
                return - 1
    
    """
    start from negative x to positive x, from negative y to positive y
    """
    def __cmp__(self, other):                
        area1 = self.__area__(self.xIndex, self.yIndex)
        area2 = self.__area__(other.xIndex, other.yIndex)
        
        if area1 > area2:
            return 1
        elif area1 < area2:
            return -1
        else:
            return self.__cmpInSameArea__(other, area1)

#        if self.xIndex > other.xIndex:
#            return 1
#        elif self.xIndex == other.xIndex:
#            if self.yIndex > other.yIndex:
#                return 1
#            elif self.yIndex < other.yIndex:
#                return -1
#            else:
#                return 0
#        else:
#            return -1
    
    """
    
    """
    def __str__(self):
        return str(self.xIndex) + ", " + str(self.yIndex) + ", " + str(self.value)
    
    """
    
    """
    def __eq__(self, other):
        if self.xIndex == other.xIndex and self.yIndex == other.yIndex:
            return True
        else:
            return False
        
    def __nq__(self, other):
        if self.xIndex == other.xIndex and self.yIndex == other.yIndex:
            return False
        else:
            return True
    
    def distance(self, other):
        dx = self.xIndex - other.xIndex
        dy = self.yIndex - other.yIndex
        return math.sqrt(dx*dx + dy*dy)
    
    def getXIndex(self):
        return self.xIndex
    
    def getYIndex(self):
        return self.yIndex
    

    